package com.xyoto.takeawayUser.controller;

import com.xyoto.takeawayUser.aspect.annotation.RequiresLogin;
import com.xyoto.takeawayUser.aspect.annotation.RequiresLogin;
import com.xyoto.takeawayUser.dto.SaveUserAddrDTO;
import com.xyoto.takeawayUser.dto.UpdateUserAddrDTO;
import com.xyoto.takeawayUser.dto.UpdateUserDTO;
import com.xyoto.takeawayUser.service.UserService;
import com.xyoto.takeawayUser.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/user")
@Api(tags = "用户模块")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getUserById")
    @ApiOperation("查询我的信息")
    @RequiresLogin
    public Result getUserById(){
        return userService.getUserById();
    }

    @PostMapping("/updateUserInfo")
    @ApiOperation("修改用户信息")
    @RequiresLogin
    public Result updateUserInfo(@RequestBody UpdateUserDTO updateUserDTO){
        return userService.updateUserInfo(updateUserDTO);
    }

    @RequiresLogin
    @ApiOperation("添加我的地址")
    @PostMapping("/addAddr")
    public Result addAddr(@Valid @RequestBody SaveUserAddrDTO saveUserAddrDTO){
        return userService.saveAddr(saveUserAddrDTO);
    }

    @RequiresLogin
    @ApiOperation("修改我的地址")
    @PostMapping("/updateUserAddr")
    public Result updateUserAddr(@Valid @RequestBody UpdateUserAddrDTO updateUserAddrDTO){
        return userService.updateUserAddr(updateUserAddrDTO);
    }
    @RequiresLogin
    @GetMapping("/getUserAddList")
    @ApiOperation("查询我的地址列表")
    public Result getUserAddList(){
        return userService.getUserAddList();
    }


}
